<?php
    $page = $_GET['page'];

if($page=='library')
{

    // $con=mysql_connect("localhost","root","");
    //$db=mysql_select_db("db_lols",$con);
    require('db_connection.php');
    $libraryName=$_POST['libraryName'];
    $address=$_POST['address'];
    $contactNo=$_POST['contactNo'];
    $description=$_POST['description'];
    //$imgfilename=''];
    $libraryNo = $_GET['libraryNo'];

    $sql = "SELECT * FROM tbllibrary";
    $result = mysql_query($sql);
    $ctr = mysql_num_rows($result)+1;
    
    //$file_name = $HTTP_POST_FILES['ufile']['name'];
    $new_file_name="$libraryNo.jpg";
    $path= "images/library/".$new_file_name;
    echo $new_file_name;
    if($ufile !=none)
    {
    if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
    {
    echo "Successful<BR/>";

    //$new_file_name = new file name
    //$HTTP_POST_FILES['ufile']['size'] = file size
    //$HTTP_POST_FILES['ufile']['type'] = type of file
    echo "File Name :".$new_file_name."<BR/>";
    echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
    echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
    }
    else
    {
        //echo "Error";
        //$new_file_name="nophoto.jpg";
    }
    }

    //$query = "INSERT INTO tbllibrary VALUES ('$libraryName','$ctr','$address','$contactNo','$description','secret')";

    $query = "UPDATE tbllibrary SET libraryName='$libraryName',address='$address',contactNo='$contactNo',description='$description',imgfilename='$new_file_name' WHERE libraryNo=$libraryNo";

    $result = mysql_query($query);


    if($result){
       // echo("Record sucessfully edited.");
        echo"'<script>document.location.href='libprofileview.php'</script>'";
//            $host  = $_SERVER['HTTP_HOST'];
//            $uri  = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
//            $extra = 'libprofileview.php';
//            header("Location: http://$host$uri/$extra");




    }else{
       echo("Adding failed.");
    }
    mysql_close();

}


?>
